package com.weijian.dal.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.Getter;

/**
 * 课程状态枚举
 * 数据库中存储为整数：0-下架，1-上架
 */
@Getter
public enum CourseStatus {
    OFFLINE(0, "下架"),
    ONLINE(1, "上架");

    @EnumValue
    private final int code;
    
    @JsonValue
    private final String description;

    CourseStatus(int code, String description) {
        this.code = code;
        this.description = description;
    }

    public static CourseStatus fromCode(int code) {
        for (CourseStatus status : values()) {
            if (status.code == code) {
                return status;
            }
        }
        throw new IllegalArgumentException("Invalid course status code: " + code);
    }
}